package com.uade.magicCompany.controler;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.uade.magicCompany.controler.utitilities.ActionConstants;
import com.uade.magicCompany.model.Usuario;
import com.uade.magicCompany.services.GestionGrupoUsuarios;
import com.uade.magicCompany.services.GestionGrupoUsuariosImpl;

public class AgregarMiembroAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 1L;
	private Map<String, Object> userSession ;
	
	private String nuevoEntrada;

	@Override
	public void setSession(Map<String, Object> session) {
		userSession = session;
	}
	
	public String execute() throws Exception {
		System.out.println("Vinculando usuario a grupo: " + nuevoEntrada);
		GestionGrupoUsuarios gestionGrupo = new GestionGrupoUsuariosImpl();
		String idVinculante = (String) ActionContext.getContext().getSession().get(ActionConstants.USER_LOGGED);
		if (idVinculante != null) {
			gestionGrupo.vincularUsuario(Long.parseLong(nuevoEntrada), Long.valueOf(idVinculante));
			return SUCCESS;
		} else {
			return "login";
		}
	}

	public String getNuevoEntrada() {
		return nuevoEntrada;
	}

	public void setNuevoEntrada(String nuevoEntrada) {
		this.nuevoEntrada = nuevoEntrada;
	}
}
